﻿using System;
using System.Collections.Generic;
using System.Text;
using LibNoise;

namespace SampleImageGenerator.Modules.Primitives
{
	internal class Gaussian : IModule
	{
		private Double m_sigma;
		private Double m_exponentFactor;

		public Double Scale { get; set; }
		public Double X { get; set; }
		public Double Y { get; set; }
		public Double Z { get; set; }

		public Gaussian()
		{
			Scale = 1;
			Sigma = 1;
			X = 0;
			Y = 0;
			Z = 0;
		}

		public Double Sigma 
		{
			get
			{
				return m_sigma;
			}
			set
			{
				m_sigma = value;
				m_exponentFactor = -1.0 / (2.0 * Sigma * Sigma);
			}
		}

		public Double GetValue(Double x, Double y, Double z)
		{
			Double dx = x - X;
			Double dy = y - Y;
			Double dz = z - Z;

			Double distanceSquared = (dx * dx) + (dy * dy) + (dz * dz);
			Double exponent = m_exponentFactor * distanceSquared;
			Double value = Scale * System.Math.Exp(exponent);
			
			return value;
		}
	}
}
